/**
 * 
 */
package edu.gtcfla.km.security.credential;
import java.util.List;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.apache.shiro.subject.PrincipalCollection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author vison
 *
 */
public class CasCredenialMatcher extends SimpleCredentialsMatcher {

    private static final Logger log = LoggerFactory.getLogger(CasCredenialMatcher.class);	



    protected boolean equals(Object tokenCredentials, List accountCredentials) {
    	String keyToken = null;
    	
    	boolean containCredentails  = false;
    	if (tokenCredentials != null) {
    		
    		String tokenCredentialsStr = tokenCredentials.toString();
    		
    		String[]  tokenCredArray =  tokenCredentialsStr.split("-");
    		
    		String inputToken = tokenCredArray[0];
    		
    		containCredentails = accountCredentials.contains( inputToken );
    		
   	
    	}
    	
    	
    	return containCredentails;

    }    

    @Override
    protected List getCredentials(AuthenticationInfo info) {
    	PrincipalCollection  priCollect = info.getPrincipals();
    	
    	List listPriColl = priCollect.asList();
    	
        return listPriColl;
    }    
    
    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        Object tokenCredentials = getCredentials(token);
        List accountCredentials = getCredentials(info);
        return equals(tokenCredentials, accountCredentials);
    } 
}
